﻿using CodingWheels.DataTypes.Core;

namespace CodingWheels.DataTypes
{
    public class FrequencyUnit : Unit
	{
		public static readonly FrequencyUnit Hertz = new FrequencyUnit("Hertz", "Hz");
		public static readonly FrequencyUnit Kilohertz = new FrequencyUnit("Kilohertz", "kHz");
		public static readonly FrequencyUnit Megahertz = new FrequencyUnit("Megahertz", "MHz");
		public static readonly FrequencyUnit Gigahertz = new FrequencyUnit("Gigahertz", "GHz");

    	private FrequencyUnit(string name, string symbol) : base(name, symbol)
		{
		}
	}

	public class Frequency : DataType<Frequency, FrequencyUnit>
	{
        public Frequency() : base(0, FrequencyUnit.Hertz)
		{	
		}

		public Frequency(double value, FrequencyUnit unit) : base(value, unit)
		{
		}
	}

	internal class FrequencyConverter : Converter<FrequencyUnit>
	{
		public FrequencyConverter()
		{
			AddConversion(Conversion<FrequencyUnit>.ConvertUsingDivision(FrequencyUnit.Hertz,
																		 FrequencyUnit.Kilohertz,
																		 1000));

			AddConversion(Conversion<FrequencyUnit>.ConvertUsingDivision(FrequencyUnit.Hertz,
																		 FrequencyUnit.Megahertz,
																		 1000000));

			AddConversion(Conversion<FrequencyUnit>.ConvertUsingDivision(FrequencyUnit.Hertz,
																		 FrequencyUnit.Gigahertz,
																		 1000000000));

			AddConversion(Conversion<FrequencyUnit>.ConvertUsingDivision(FrequencyUnit.Kilohertz,
																		 FrequencyUnit.Megahertz,
																		 1000));

			AddConversion(Conversion<FrequencyUnit>.ConvertUsingDivision(FrequencyUnit.Kilohertz,
																		 FrequencyUnit.Gigahertz,
																		 1000000));

			AddConversion(Conversion<FrequencyUnit>.ConvertUsingDivision(FrequencyUnit.Megahertz,
																		 FrequencyUnit.Gigahertz,
																		 1000));
		}
	}
}
